package lt.hsu.product.vo.convert;

import lt.hsu.product.entities.ProductEntity;
import lt.hsu.product.vo.ProductInfoRes;
import lt.hsu.product.vo.req.AddProductReq;
import org.springframework.util.Assert;

public class ProductReqToEntity {

    public static ProductEntity convert(AddProductReq productReq){
        Assert.isTrue(productReq != null ,"添加产品参数不能为空");
        ProductEntity productEntity = new ProductEntity();
        productEntity.setCode(productReq.getProductCode());
        productEntity.setName(productReq.getProductName());
        return productEntity;
    }

    public static ProductInfoRes convert(ProductEntity productEntity){
        ProductInfoRes productInfoRes = new ProductInfoRes();
        productInfoRes.setCode(productEntity.getCode());
        productInfoRes.setName(productEntity.getName());
        productInfoRes.setId(productEntity.getId());
        return productInfoRes;
    }

}
